package com.elm_springboot_s.mapper;

import com.elm_springboot_s.pojo.Cart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CartMapper {
    
    @Select("SELECT * FROM cart WHERE userId = #{userId}")
    List<Cart> listCartByUserId(Long userId);
    
    @Select("SELECT * FROM cart WHERE userId = #{userId} AND businessId = #{businessId}")
    List<Cart> listCartByUserIdAndBusinessId(Long userId, Integer businessId);
    
    @Insert("INSERT INTO cart (userId, businessId, foodId, quantity) VALUES (#{userId}, #{businessId}, #{foodId}, 1)")
    int saveCart(Long userId, Integer businessId, Integer foodId);
    
    @Update("UPDATE cart SET quantity = #{quantity} WHERE userId = #{userId} AND businessId = #{businessId} AND foodId = #{foodId}")
    int updateCart(Long userId, Integer businessId, Integer foodId, Integer quantity);
    
    @Delete("DELETE FROM cart WHERE userId = #{userId} AND businessId = #{businessId} AND foodId = #{foodId}")
    int removeCartByUserIdAndBusinessIdAndFoodId(Long userId, Integer businessId, Integer foodId);
    
    @Delete("DELETE FROM cart WHERE userId = #{userId} AND businessId = #{businessId}")
    int removeCartByUserIdAndBusinessId(Long userId, Integer businessId);
} 